#pragma once

#include"Poller.h"
#include"Timestamp.h"

#include<vector>
#include<sys/epoll.h>

class Channel;

//对epoll的封装，epoll_create epoll_ctl epoll_wait
class EPollPoller:public  Poller{
public:
    //后加override，告诉编译器覆盖父类方法
    EPollPoller(EventLoop* Loop);
    ~EPollPoller() override;

    //重写基类的抽象方法
    Timestamp poll(int timeoutMs, ChannelList *activeChannels) override;
    void updateChannel(Channel* channel) override;
    void removeChannel(Channel* Channel) override;
private:
    static const int kInitEventListSize = 16;
    //填写活跃连接
    void fillActiveChannels(int numEvents, ChannelList *activeChannels) const;
    //更新channel 
    void update(int operation, Channel* channel);

    //epoll_wait第二个参数
    using EventList = std::vector<epoll_event>;

    int epollfd_;
    EventList events_;
};